<?php

/*
 *Copyright (C), WhiteBlue
 *File name: dispatcher.php
 *Author: Version: 2015.3.9
 *Description: 路径分发
 */

class dispatcher
{
    public static function dispatch($router)
    {
        global $app;
        $controller = $router->getController();
        $action = $router->getAction();
        $controller_file = "app/controllers/{$controller}.php";
        if (file_exists($controller_file)) {
            require_once($controller_file);
            $app = new $controller();
            $app->setMethod($router->getMethod());
            $app->setParams($router->getParams());
            $app->$action();
            if (config('isDebug') == false)
                ob_clean();
            else
                ob_flush();
        } else {
            echo 'ERROR 404:page not find' . '<br>';
        }
    }
}